<?php

	// No direct access
	defined('_JEXEC') or die;

	class LanguageHelper {

		public static function getLanguages() {
			$db =& JFactory::getDbo();
			$db->setQuery(
				'SELECT sef, title, title_native, lang_code' .
				' FROM #__languages' .
				' ORDER BY ordering ASC'
			);
			$languages = $db->loadObjectList();
			return $languages;
		}

		public static function getLanguageIndex($languages) {
			$lang = JFactory::getLanguage();
			$langIndex = 0;
			$item = null;
			foreach($languages as $candidateLang) {
				$langIndex ++;
				if ($lang->getTag() == $candidateLang->lang_code) {
					break;
				}
			}
			if ($langIndex > count($languages)) {
				$langIndex = 1;
			}
			return $langIndex;
		}

	}